<?php

namespace app\models\dao;

use Yii;

/**
 * This is the model class for table "{{%admin}}".
 *
 * @property integer $id
 * @property string $username
 * @property string $password
 * @property string $nick
 * @property string $access_token
 * @property string $auth_key
 * @property integer $role_id
 * @property string $ip
 * @property string $photo
 * @property integer $sex
 * @property string $phone
 * @property string $email
 * @property string $qq
 * @property string $description
 * @property integer $countlog
 * @property integer $status
 * @property integer $is_freeze
 * @property string $lastlogin_time
 * @property integer $flag
 * @property string $create_time
 * @property string $update_time
 */
class Admin extends \app\common\PopToolActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%admin}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['username', 'password'], 'required'],
            [['role_id', 'sex', 'countlog', 'status', 'is_freeze', 'flag'], 'integer'],
            [['description'], 'string'],
            [['lastlogin_time', 'create_time', 'update_time'], 'safe'],
            [['username', 'email'], 'string', 'max' => 50],
            [['password'], 'string', 'max' => 100],
            [['nick'], 'string', 'max' => 20],
            [['access_token', 'auth_key'], 'string', 'max' => 200],
            [['ip'], 'string', 'max' => 15],
            [['photo'], 'string', 'max' => 255],
            [['phone'], 'string', 'max' => 11],
            [['qq'], 'string', 'max' => 13],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '管理员ID',
            'username' => '管理员用户名',
            'password' => '管理员密码',
            'nick' => '昵称',
            'access_token' => 'access_token',
            'auth_key' => 'auth_key',
            'role_id' => '角色ID',
            'ip' => '管理员登陆IP',
            'photo' => '管理员头像',
            'sex' => '性别 0：保密 1：男 2：女',
            'phone' => '手机',
            'email' => 'Email',
            'qq' => 'QQ',
            'description' => '描述',
            'countlog' => '登陆次数',
            'status' => '启用/停用,1：启用，0：停用',
            'is_freeze' => '是否冻结：0.否，1.是',
            'lastlogin_time' => '最后登陆时间',
            'flag' => 'Flag',
            'create_time' => '创建时间',
            'update_time' => '更新时间',
        ];
    }

    public function getrole(){
        return $this->hasOne(Role::className(), ['id' => 'role_id']);
    }
}
